package com.nmp;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

public class ServiceDaemon {

    private static final Logger logger = Logger.getLogger(ServiceDaemon.class);
    private static WebServer webServer = null;
    
    public static void main(String[] args) {
        try {
            PropertyConfigurator.configure("./conf/log4j.ini");
            webServer = WebServer.getInstance();
            new Thread(webServer).start();
            
            Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        logger.info("Shutdown thread before webserver getinstance");
                        if(webServer != null)
                            webServer.stop();
                    } catch (Exception e) {}
                }
            }, "Stop Jetty Hook"));
            
        } catch (Exception e) {
            logger.error("Exception encountered during startup: " + e.getMessage());
        }
    }
}
